<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">

    <link rel="stylesheet" href="__PUBLIC__/build/css/layui.css">

    <style>
        body{padding: 10px;}
    </style>
</head>
<body>

<form class="layui-form layui-form-pane1" method="post" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">上级菜单</label>
        <div class="layui-input-block">
            <select name="pid">
                <option value="0">顶级菜单</option>
                <volist name="menu_rows" id="vo">
                    <option value="{$vo.pk_id}" <if condition="$vo['pk_id'] eq $menu['pid']">selected</if>>{$vo.title_show}</option>
                </volist>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">菜单名</label>
        <div class="layui-input-block">
            <input type="text" name="name" value="{$menu.name}" required placeholder="请输入菜单名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">菜单地址</label>
        <div class="layui-input-block">
            <input type="text" name="control" value="{$menu.control}" placeholder="如System/Active/index,顶级菜单后两级可随意，如System/sfas/sdggs" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">可操作功能</label>
        <div class="layui-input-block">
            <volist name="action" id="vo">
                <input type="checkbox" name="access[]" value="{$vo.action}"  title="{$vo.name}" <if condition="in_array($vo['action'],$access_op)">checked</if>>
            </volist>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <input type="hidden" name="pk_id" value="{$menu['pk_id']}">
            <button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>


<script src="__PUBLIC__/build/layui.js"></script>
<script>
    layui.use('form', function(){
        var $ = layui.jquery,form = layui.form();

        //自定义验证规则
        form.verify({
            title: function(value){
                if(value.length < 2){
                    return '标题也太短了吧';
                }
            }
//            ,pass: [/(.+){6,12}$/, '密码必须6到12位']
        });

        //监听提交
        form.on('submit(*)', function(data){
            var btnName = $(data.elem).text();
            var submit = $(data.elem).attr('disabled',true).addClass('layui-btn-disabled').text('处理中');

            $.post(data.action,$('form').serialize(), function (data) {
                submit.attr('disabled',false).removeClass('layui-btn-disabled').text(btnName);
                window.history.back();
            });
            return false;
        });
    });
</script>
</body>
</html>
